package cn.net.wangyixinwen.test;

import android.util.Log;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import cn.net.wangyixinwen.bean.OrderBean;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

public class OrderModule extends ViewModel {
    private OrderRepository repository ;
    private MutableLiveData<OrderBean> liveData = new MutableLiveData<>() ;

    public OrderModule(){
        repository = null ;
    }
    public void setModel(){
        this.repository = new OrderRepository() ;
    }

    public void getData(){
        repository.getData()
                .subscribe(new Observer<OrderBean>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }
                    @Override
                    public void onNext(@NonNull OrderBean orderBean) {
                        if (orderBean!= null){
                            liveData.postValue(orderBean);
                        }
                    }
                    @Override
                    public void onError(@NonNull Throwable e) {
                        Log.d("数据获取失败", "onError: " + e.getMessage());
                    }
                    @Override
                    public void onComplete() {

                    }
                }) ;
    }
    public MutableLiveData<OrderBean> getLiveData(){
        return liveData ;
    }
}
